package com.spzx.cart.api;

import com.spzx.cart.api.domain.CartInfo;
import com.spzx.cart.api.factory.RemoteCartFallbackFactory;
import com.spzx.common.core.constant.ServiceNameConstants;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;

import java.util.List;

/**
 * @author Haoran Sun
 * @since 2024/07/31
 */
@FeignClient(contextId = "remoteCartService",
        value = ServiceNameConstants.CART_SERVICE,
        fallbackFactory = RemoteCartFallbackFactory.class
)
public interface RemoteCartService {
    /**
     * 更新购物车选中商品的价格---> 在提交订单前需要校验订单中商品的价格
     * @param userId 用户id
     * @param source 源-判断是否为内部调用
     * @return 是否更新成功
     */
    @GetMapping("/updateCartPrice/{userId}")
    R<Boolean> updateCartPrice(@PathVariable("userId") Long userId,
                               @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 删除购物车选中商品--->在提交订单后需要在购物车中删除已提交订单的商品
     * @param userId 用户id
     * @param source 源-判断是否为内部调用
     * @return 是否删除成功
     */
    @GetMapping("/deleteCartCheckedList/{userId}")
    R<Boolean> deleteCartCheckedList(@PathVariable("userId") Long userId,
                                     @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    @GetMapping("/getCartCheckedList/{userId}")
    R<List<CartInfo>> getCartCheckedList(@PathVariable("userId") Long userId,
                                                @RequestHeader(SecurityConstants.FROM_SOURCE)String source);
}
